﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.Department
{
    public class DepartmentPresenter : Presenter<IDepartmentView>
    {
        public DepartmentPresenter(IDepartmentView view)
            : base(view)
        {
        }

        public void Display(string departmentId)
        {
            if (departmentId == null) return;

            var department = Model.GetDepartment(departmentId);

            View.DepartmentID = department.DepartmentID;
            View.DepartmentCode = department.DepartmentCode;
            View.DepartmentName = department.DepartmentName;
            View.Description = department.Description;
            View.IsActive = department.IsActive;
            View.IsParent = department.IsParent;
            View.ParentDepartmentID = department.ParentDepartmentID;
            View.RestaurantId = department.RestaurantId;
        }

        public int Save()
        {
            var department = new DepartmentModel
            {
                DepartmentID = View.DepartmentID,
                DepartmentCode = View.DepartmentCode,
                DepartmentName = View.DepartmentName,
                Description = View.Description,
                IsActive = View.IsActive,
                IsParent = View.IsParent,
                ParentDepartmentID = View.ParentDepartmentID,
                RestaurantId = View.RestaurantId
            };

            if (View.DepartmentID == null)
                return Model.AddDepartment(department);
            else
                return Model.UpdateDepartment(department);
        }

        public int Delete(string departmentId)
        {
            return Model.DeleteDepartment(departmentId);
        }
    }
}
